package com.bwie.service.impl;

import cn.hutool.core.io.file.FileNameUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.Galldate;
import com.bwie.pojo.Gallery;
import com.bwie.service.GalleryService;
import com.bwie.mapper.GalleryMapper;
import com.bwie.utils.R;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
* @author 36167
* @description 针对表【gallery(美术馆表)】的数据库操作Service实现
* @createDate 2025-03-06 09:43:01
*/
@Service
public class GalleryServiceImpl extends ServiceImpl<GalleryMapper, Gallery>
    implements GalleryService{

    @Autowired
    GalleryMapper galleryService;

    @Autowired
    FastFileStorageClient fastFileStorageClient;

    @Override
    public R upload(MultipartFile file) {
      String url="";
        try {
        url=  fastFileStorageClient.uploadFile(file.getInputStream(),file.getSize(),
                    FileNameUtil.extName(file.getOriginalFilename()),null).getFullPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.OK(url);
    }

    @Override
    public List<Gallery> list1() {
       List<Gallery> list=  galleryService.list();
       return list;
    }

    @Override
    public List<Galldate> showdate(Integer gid) {
       List<Galldate> list= galleryService.showdate(gid);
       return list;
    }
}




